<?php
include 'seguranca.php';
include 'Model/Usuario.php';
include 'Model/DAO/UsuarioDAO.php';
protegePagina();

if (isset($_POST) && !empty($_POST))
{
    // Validacao dos dados
    $nome  = addslashes($_POST['nome']);
    $login = addslashes($_POST['usuario']);
    $email = addslashes($_POST['email']);
    $senha = md5($_POST['senha']);

    $usuario = new Usuario();
    $usuario->setNomeUsuario($nome);
    $usuario->setUsuario($login);
    $usuario->setEmailUsuario($email);
    $usuario->setSenhaUsuario($senha);

    $usuarioDAO = new UsuarioDAO();
    $usuarioDAO->addUsuario($usuario);

    $msg = '';
    if ($usuarioDAO) {
      $msg = 'Usuário cadastrado com sucesso';
      header('Location: usuario_list.php?pag=1');
    }
    else {
      $msg = 'Ocorreu um erro tente novamente';
      header('Location: usuario_cad.php');
    }
      
}

?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='pt-br' lang='pt-br'>
    <head>
        <meta http-equiv='content-type' content='text/html; charset=utf-8' />
        <meta http-equiv='content-language' content='pt-br' />
        <meta name='robots' content='noindex,nofollow' />
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/reset.css' /> <!-- RESET -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/main.css' /> <!-- MAIN STYLE SHEET -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/2col.css' title='2col' /> <!-- DEFAULT: 2 COLUMNS -->
        <link rel='alternate stylesheet' media='screen,projection' type='text/css' href='css/1col.css' title='1col' /> <!-- ALTERNATE: 1 COLUMN -->
        <!--[if lte IE 6]><link rel='stylesheet' media='screen,projection' type='text/css' href='css/main-ie6.css' /><![endif]--> <!-- MSIE6 -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/style.css' /> <!-- GRAPHIC THEME -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/mystyle.css' /> <!-- WRITE YOUR CSS CODE HERE -->
        <script type='text/javascript'src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
        <script type='text/javascript' src='http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js'></script>
        <script type='text/javascript' src="js/insertUsuario.js"></script>
        <script type='text/javascript' src='js/jquery.switcher.js'></script>
        <script type='text/javascript' src='js/toggle.js'></script>
        <title>Usuário</title>
    </head>
    <body>
        <div id='main'>
            <?php include 'includes/inc_header.php' ?>
            <?php include 'includes/inc_menu.php' ?>
    <!-- Columns -->
    <div id='cols' class='box'><?php include 'includes/left-colum-cad.php'?></div>

    <!-- Content (Right Column) -->
    <div id='content' class='box'>
        <h1>Cadastro de Usuários</h1>
        <p class='msg info' id='resposta'><?=@$msg?></p>
        <p class='msg error' id='error'></p>

        <form action='' method='post' id='formUser'>
            <fieldset>
                <legend></legend>
                <p class='nomt'>
                    <label for='nome' class='req'>Nome:</label><br />
                    <input type='text' size='60' name='nome' class='input-text required' id='nome' value=''   />
                </p>
                <p class='nomt'>
                    <label for='usuario' class='req'>Usuário:</label><br />
                    <input type='text' name='usuario' class='input-text required'  id='usuario' size='60'  />
                </p>
                <p class='nomt'>
                    <label for='email' class='req'>Email:</label><br />
                    <input type='text' name='email' class='input-text required' id='email' size='60'  />
                </p>
                <p class='nomt'>
                    <label for='senha' class='req'>Senha:</label><br />
                    <input type='password' name='senha' class='input-text required' id='senha'    size='60' />
                </p>
                <p class='nomt'>
                    <label for='conf_senha' class='req'>Confirmar Senha:</label><br />
                    <input type='password' name='conf_senha' class='input-text required' id='conf_senha' size='60'   />
                </p>
                <p><input type='submit' id='enviaUsuario' value='Enviar' /></p>
            </fieldset>
        </form>
    </div>
</div> 
<?php include 'includes/inc_footer.php' ?>